﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace QLua;

public class ProxyType
{
	private readonly Type _proxy;

	public ProxyType(Type proxy)
	{
		_proxy = proxy;
	}

	/// <summary>
	/// Provide human readable short hand for this proxy object
	/// </summary>
	/// <returns></returns>
	public override string ToString()
	{
		return "ProxyType(" + UnderlyingSystemType + ")";
	}

	public Type UnderlyingSystemType => _proxy;

	public override bool Equals(object obj)
	{
		if (obj is Type)
			return _proxy == (Type)obj;
		if (obj is ProxyType)
			return _proxy == ((ProxyType)obj).UnderlyingSystemType;
		return _proxy.Equals(obj);
	}

	public override int GetHashCode()
	{
		return _proxy.GetHashCode();
	}

	public MemberInfo[] GetMember(string name, BindingFlags bindingAttr)
	{
		return LuaMemberAttribute.GetMembersForType(_proxy, name, bindingAttr);
	}

	public MethodInfo GetMethod(string name, BindingFlags bindingAttr, Type[] signature)
	{
		return LuaMemberAttribute.GetMethodsForType(_proxy, name, bindingAttr, signature).FirstOrDefault();
	}
}
